package com.lijie.bs_recruit.controller;


import com.github.pagehelper.PageInfo;
import com.lijie.bs_recruit.VO.ResultVO;
import com.lijie.bs_recruit.model.Jobcollection;
import com.lijie.bs_recruit.service.JobcollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lijie
 * @since 2021-04-07
 */
@RestController
@RequestMapping("/jobCollection")
public class JobcollectionController {

    @Autowired
    JobcollectionService jobcolService;

    //添加收藏记录
    @RequestMapping("/addJobCollection")
    public String addJobCollection(@RequestBody Jobcollection jobcollection){
        String result="";
        Jobcollection jobCollection = jobcolService.getJobCollection(jobcollection,null);
        if(jobCollection!=null){
            if(jobCollection.getIsDeleted()==1){//收藏过但是删除了,所以将1 变为0
                jobcolService.changeIsDeleted(jobcollection, 0);
                result="succ";
            }
        }else{
            boolean save = jobcolService.save(jobcollection);
            if(save){
                result="succ";
            }else{
                result="error";
            }
        }

        return result;
    }
    //查询收藏记录，判断是否收藏
    @RequestMapping("/selJobCollection")
    public ResultVO<Jobcollection> selJobCollection(@RequestBody Jobcollection jobcollection){
        ResultVO<Jobcollection> result=new ResultVO<>();
        Jobcollection jobCollection = jobcolService.getJobCollection(jobcollection,0);
        if(jobCollection!=null){
            result.setMessage("succ");
            result.setObject(jobCollection);
        }else{
            result.setMessage("none");
        }
        return result;
    }
    //删除收藏记录
    @RequestMapping("/deleteJobCollection")
    public String deleteJobCollection(@RequestBody Jobcollection jobcollection){
        String result="";
        Boolean aBoolean = jobcolService.changeIsDeleted(jobcollection, 1);
        if(aBoolean){
            result="succ";
        }else{
            result="error";
        }
        return result;
    }

    //user查看自己的收藏记录
    @RequestMapping("/selJobCollectionByUserId/{pageIndex}")
    public PageInfo<Jobcollection> selJobCollByUserId(@PathVariable Integer pageIndex ,@RequestBody Jobcollection jobcollection){
        return jobcolService.selJobCollectionByUserId(pageIndex,jobcollection);
    }


}

